package elkaiyohrempfeil;

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Graphics;

import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JSplitPane;

public class MainFrame extends JFrame
{       
    private MapFrame map;
    private MenuBar menu;
    private JPanel layer;
    private JSplitPane splitPane;
    private StatusBar statusbar;
        
    public MainFrame() 
    {
        super("GIS4Ships");
        setPreferredSize(new Dimension(800, 600));
        setLocation(100,100);
        
        splitPane = new JSplitPane();
        splitPane.setOrientation(JSplitPane.HORIZONTAL_SPLIT);
         
        menu = new MenuBar(this);
        layer = new LayerTree();
//        map = new MapFrame();
        statusbar = new StatusBar();
        
        splitPane.setLeftComponent(layer);
        splitPane.setRightComponent(map);
        this.setJMenuBar(menu);

        add(statusbar,BorderLayout.SOUTH);
        add(splitPane,BorderLayout.CENTER);
        pack();
        setVisible(true);
    }

	/*
     * Method for switching on and off the Statusbar.
     */
    public void switchStatusbar()
    {
            if (statusbar.isValid()) 
            {
                    remove(statusbar);
            } 
            else 
            {
                    add(statusbar,BorderLayout.SOUTH);
            }
            
        pack();
        setVisible(true);
    }
    
    public void openFile()
    {
        JFileChooser fc = new JFileChooser();
        fc.getFileView();
        fc.setDialogTitle("Choose a file to open");
        fc.showOpenDialog(null);
        String filepath = fc.getSelectedFile().getPath();
        //TODO:Call parser with filepath
    }
}
